/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/parser/deserializer/ArrayListStringFieldDeserializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: ArrayListStringFieldDeserializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.parser.deserializer;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Map;

import com.elancom.framework.commons.json.parser.DefaultJSONParser;
import com.elancom.framework.commons.json.parser.JSONLexer;
import com.elancom.framework.commons.json.parser.JSONToken;
import com.elancom.framework.commons.json.parser.ParserConfig;
import com.elancom.framework.commons.json.util.FieldInfo;

public class ArrayListStringFieldDeserializer extends FieldDeserializer {

	public ArrayListStringFieldDeserializer(ParserConfig mapping, Class<?> clazz, FieldInfo fieldInfo) {
		super(clazz, fieldInfo);

	}

	@Override
	public int getFastMatchToken() {
		return JSONToken.LBRACKET;
	}

	@Override
	public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
		ArrayList<Object> list;

		final JSONLexer lexer = parser.getLexer();
		if (lexer.token() == JSONToken.NULL) {
			lexer.nextToken(JSONToken.COMMA);
			list = null;
		} else {
			list = new ArrayList<Object>();

			ArrayListStringDeserializer.parseArray(parser, list);
		}
		if (object == null) {
			fieldValues.put(fieldInfo.getName(), list);
		} else {
			setValue(object, list);
		}
	}
}
